package com.hdy.orderforthree.widget;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import com.hdy.orderforthree.R;

/**
 * 点击弹框外区域，自动关闭弹框
 */
public class CenterDialogPop extends BasePop {

    public CenterDialogPop(int addLayoutId, Context context){
        super(R.id.main_content, addLayoutId, context);
        if (((ViewGroup)mLayout).getChildCount() > 0) {
            View view = ((ViewGroup) mLayout).getChildAt(0);
            view.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
        }
        mLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    removeView();
                }
                return true;
            }
        });
    }
}
